package com.itboye.eweilisten.me.home;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.eweilisten.R;
import com.itboye.eweilisten.base.BaseActivity;
import com.itboye.eweilisten.util.loadingutil.MAlert;
import com.itboye.eweilisten.util.sputil.Const;
import com.itboye.eweilisten.util.widget.PasswordInputView;
import com.itboye.eweilisten.util.widget.XImageLoader;

/**
 * 确认订单
 */
public class ActivityGoodsOrderActivity extends BaseActivity {
    private TextView tvTitle;
    private ImageView back;
    private TextView tvokOrder;//提交订单
    private String title;
    String countment;
    String price;
    String sku_pkid;
    String math;
    String id;
    String imgid;

    EditText tv_code;

    private TextView tvOrderTitle;//标题
    private TextView tvMath;//月份
    private TextView tvpriceOrder;//价格/每一个
    private TextView tvCha;//biaoti
    private TextView tvOrderPrice;//共计多少
    ImageView imgBook;//图片
    private TextView tvGongji;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);

        setContentView(R.layout.activity_goods_order);
        tvTitle.setText("确认订单");
        countment = getIntent().getStringExtra("countment");
        price = getIntent().getStringExtra("price");
        sku_pkid = getIntent().getStringExtra("sku_pkid");
        math = getIntent().getStringExtra("math");
        id = getIntent().getStringExtra("id");
        imgid = getIntent().getStringExtra("imgid");
        init();

        //购物结束的广播
        IntentFilter filter = new IntentFilter(ActivityShopPlay.GOUWUINEXIT);
        registerReceiver(gouwuReceiver, filter);
    }

    BroadcastReceiver gouwuReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            finish();
        }
    };

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(gouwuReceiver);
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.back:
                this.finish();
                break;
            case R.id.tvokOrder:
                if (tv_code.getText().toString().trim().equals("")) {
                    MAlert.alert("请输入推荐码");
                }else {
                    Intent intent = new Intent(ActivityGoodsOrderActivity.this, ActivityShopPlay.class);
                    intent.putExtra("price", price);//价格
                    intent.putExtra("sku_pkid", sku_pkid);
                    intent.putExtra("note", "");//留言(已删，暂时不需要)
                    intent.putExtra("idcode", tv_code.getText().toString());//邀请码
                    intent.putExtra("type", "liji");
                    startActivity(intent);
                }
                break;
        }
    }

    public void init() {
        tvOrderTitle.setText(countment);//标题
        tvMath.setText(math);//月份
        tvpriceOrder.setText("¥" + price);//价格/每一个
        tvGongji.setText("共一件商品，合计¥" + price);
        tvOrderPrice.setText("¥" + price);
        XImageLoader.load(Const.IMAGE_HEAD + imgid, imgBook);

        tv_code = (EditText) findViewById(R.id.invite_code);

    }
}
